package com.ohos.liveeventbus.ipc.receiver;


import com.ohos.liveeventbus.LiveEventBus;
import com.ohos.liveeventbus.ipc.consts.IpcConst;
import com.ohos.liveeventbus.ipc.core.ProcessorManager;
import com.ohos.liveeventbus.logger.Log;
import ohos.aafwk.content.Intent;
import ohos.event.commonevent.CommonEventData;
import ohos.event.commonevent.CommonEventSubscribeInfo;
import ohos.event.commonevent.CommonEventSubscriber;

/**
 * Created by liaohailiang on 2019/3/26.
 */
public class LebIpcReceiver extends CommonEventSubscriber {
    private static final String TAG = "LebIpcReceiverLog";

    public LebIpcReceiver(CommonEventSubscribeInfo subscribeInfo) {
        super(subscribeInfo);
    }

    @Override
    public void onReceiveEvent(CommonEventData commonEventData) {
        Intent intent = commonEventData.getIntent();
        if (IpcConst.ACTION.equals(intent.getAction())) {
            Log.i(TAG,"get comm event,action:"+ IpcConst.ACTION);
            try {
                String key = intent.getStringParam(IpcConst.KEY);
                Object value = ProcessorManager.getManager().createFrom(intent);
                if (key != null && value != null) {
                    LiveEventBus.get(key).post(value);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
